/*******************************************************************************
 * Copyright:   Copyright (c) 2007. Hisilicon Technologies, CO., LTD.
 * Version:     V300R001B01
 * Filename:    vKeyMap.c
 * Description:
                Exports ScanCodeToVKey for the PDD to use to map scan codes to virtual
                keys.  A version of this will be needed for every physical/virtual key
                configuration.
 * History:
                1.Created by SunShaojie on 2008/11/28
*******************************************************************************/


#include <windows.h>
#include <ceddk.h>
#include <Winuserm.h>
#include <Dbgapi.h>

#include "option.h"
#include "keypad.h"
#include "hisi6810_kpc.h"
#include "kbd_share.h"

//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
//defiend for rock key
#define VK_ROCKUP       0xBA
#define VK_ROCKDN       0xBB
#define VK_ROCKACT      0xBC

#ifndef dimof
    #define dimof(x)    (sizeof(x)/sizeof(x[0]))
#endif


//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
//
// Typical phone keypad maps to VK as shown below.
// Some keys might not be present, e.g. VK_TFLIP
//
// SOFTKEY1     softkey2    VK_TSOFT1, VK_TSOFT2
//          ^               VK_TUP
//      <   +   >           VK_TLEFT, VK_TACTION, VK_TRIGHT
//          v               VK_TDOWN
//  home        back        VK_THOME, VK_TBACK
//  talk        end         VK_TTALK, VK_TEND
//  1       2       3       VK_T0..VK_T9
//  4       5       6       ...
//  7       8       9       ...
//  *       0       #       VK_TSTAR, VK_TPOUND
//
// Oher buttons include
//  VK_TRECORD
//  VK_TPOWER, VK_TVOLUMEUP, VK_TVOLUMEDOWN
//  VK_TFLIP

// the table used for scan key code mapping to virtual key code.
UINT8 g_ucScToVkTable[] =
{
#ifdef KEDPAD_B831
    VK_TTALK,       // Scan Code 0x0, Prog
    VK_TLEFT,       // Scan Code 0x1
    VK_TSOFT2,      // Scan Code 0x2
    0,              // Scan Code 0x3
    0,              // Scan Code 0x4
    0,              // Scan Code 0x5
    0,              // Scan Code 0x6
    0,              // Scan Code 0x7
    VK_TUP,         // Scan Code 0x8
    VK_TACTION,     // Scan Code 0x9
    VK_TDOWN,       // Scan Code 0xA
    0,              // Scan Code 0xB
    0,              // Scan Code 0xC
    0,              // Scan Code 0xD
    0,              // Scan Code 0xE
    0,              // Scan Code 0xF
    VK_TEND,        // Scan Code 0x10
    VK_TRIGHT,      // Scan Code 0x11
    VK_TSOFT1,      // Scan Code 0x12
    0,              // Scan Code 0x13
    0,              // Scan Code 0x14
    0,              // Scan Code 0x15
    0,              // Scan Code 0x16
    0,              // Scan Code 0x17
    VK_TVOLUMEUP,   // Scan Code 0x18
    VK_FOCUS,       // Scan Code 0x19
    VK_TBACK,       // Scan Code 0x1A
    0,              // Scan Code 0x1B
    0,              // Scan Code 0x1C
    0,              // Scan Code 0x1D
    0,              // Scan Code 0x1E
    0,              // Scan Code 0x1F
    VK_TVOLUMEDOWN, // Scan Code 0x20
    VK_APP3,        // Scan Code 0x21
    0,              // Scan Code 0x22
    0,              // Scan Code 0x23
    0,              // Scan Code 0x24
    0,              // Scan Code 0x25
    0,              // Scan Code 0x26
    0,              // Scan Code 0x27
    0,              // Scan Code 0x28
    0,              // Scan Code 0x29
    0,              // Scan Code 0x2A
    0,              // Scan Code 0x2B
    0,              // Scan Code 0x2C
    0,              // Scan Code 0x2D
    0,              // Scan Code 0x2E
    0,              // Scan Code 0x2F
    0,              // Scan Code 0x30
    0,              // Scan Code 0x31
    0,              // Scan Code 0x32
    0,              // Scan Code 0x33
    0,              // Scan Code 0x34
    0,              // Scan Code 0x35
    0,              // Scan Code 0x36
    0,              // Scan Code 0x37
    0,              // Scan Code 0x38
    0,              // Scan Code 0x39
    0,              // Scan Code 0x3A
    0,              // Scan Code 0x3B
    0,              // Scan Code 0x3C
    0,              // Scan Code 0x3D
    0,              // Scan Code 0x3E
    0,              // Scan Code 0x3F
#endif
#ifdef KEDPAD_MOBILEXP
    VK_ROCKACT,     // Scan Code 0x0, Prog
    VK_APP3,        // Scan Code 0x1
    VK_TSOFT1,      // Scan Code 0x2
    VK_TLEFT,       // Scan Code 0x3
    VK_TTALK,       // Scan Code 0x4
    0,              // Scan Code 0x5
    0,              // Scan Code 0x6
    0,              // Scan Code 0x7
    VK_ROCKDN,      // Scan Code 0x8
    VK_TVOLUMEDOWN, // Scan Code 0x9
    VK_TUP,         // Scan Code 0xA
    VK_TACTION,     // Scan Code 0xB
    VK_TDOWN,       // Scan Code 0xC
    0,              // Scan Code 0xD
    0,              // Scan Code 0xE
    0,              // Scan Code 0xF
    VK_ROCKUP,      // Scan Code 0x10
    VK_TVOLUMEUP,   // Scan Code 0x11
    VK_TSOFT2,      // Scan Code 0x12
    VK_TRIGHT,      // Scan Code 0x13
    VK_TEND,        // Scan Code 0x14
    0,              // Scan Code 0x15
    0,              // Scan Code 0x16
    0,              // Scan Code 0x17
    0,              // Scan Code 0x18
    0,              // Scan Code 0x19
    0,              // Scan Code 0x1A
    VK_APP1,        // Scan Code 0x1B
    VK_APP2,        // Scan Code 0x1C
    0,              // Scan Code 0x1D
    0,              // Scan Code 0x1E
    0,              // Scan Code 0x1F
    0,              // Scan Code 0x20
    0,              // Scan Code 0x21
    0,              // Scan Code 0x22
    0,              // Scan Code 0x23
    0,              // Scan Code 0x24
    0,              // Scan Code 0x25
    0,              // Scan Code 0x26
    0,              // Scan Code 0x27
    0,              // Scan Code 0x28
    0,              // Scan Code 0x29
    0,              // Scan Code 0x2A
    0,              // Scan Code 0x2B
    0,              // Scan Code 0x2C
    0,              // Scan Code 0x2D
    0,              // Scan Code 0x2E
    0,              // Scan Code 0x2F
    0,              // Scan Code 0x30
    0,              // Scan Code 0x31
    0,              // Scan Code 0x32
    0,              // Scan Code 0x33
    0,              // Scan Code 0x34
    0,              // Scan Code 0x35
    0,              // Scan Code 0x36
    0,              // Scan Code 0x37
    0,              // Scan Code 0x38
    0,              // Scan Code 0x39
    0,              // Scan Code 0x3A
    0,              // Scan Code 0x3B
    0,              // Scan Code 0x3C
    0,              // Scan Code 0x3D
    0,              // Scan Code 0x3E
    0,              // Scan Code 0x3F
#endif
#ifdef KEDPAD_TERMINAL
    0,              // Scan Code 0x0, Prog
    VK_TVOLUMEUP,   // Scan Code 0x1
    VK_TVOLUMEDOWN, // Scan Code 0x2
    0,              // Scan Code 0x3
    VK_TEND,        // Scan Code 0x4
    0,              // Scan Code 0x5
    0,              // Scan Code 0x6
    0,              // Scan Code 0x7
    0,              // Scan Code 0x8
    VK_APP1,        // Scan Code 0x9
    VK_TUP,         // Scan Code 0xA
    VK_TLEFT,       // Scan Code 0xB
    VK_TACTION,     // Scan Code 0xC
    0,              // Scan Code 0xD
    0,              // Scan Code 0xE
    0,              // Scan Code 0xF
    0,              // Scan Code 0x10
    VK_APP3,        // Scan Code 0x11
    VK_TDOWN,       // Scan Code 0x12
    VK_TRIGHT,      // Scan Code 0x13
    VK_TTALK,       // Scan Code 0x14
    0,              // Scan Code 0x15
    0,              // Scan Code 0x16
    0,              // Scan Code 0x17
    0,              // Scan Code 0x18
    0,              // Scan Code 0x19
    0,              // Scan Code 0x1A
    0,              // Scan Code 0x1B
    0,              // Scan Code 0x1C
    0,              // Scan Code 0x1D
    0,              // Scan Code 0x1E
    0,              // Scan Code 0x1F
    0,              // Scan Code 0x20
    0,              // Scan Code 0x21
    0,              // Scan Code 0x22
    0,              // Scan Code 0x23
    0,              // Scan Code 0x24
    0,              // Scan Code 0x25
    0,              // Scan Code 0x26
    0,              // Scan Code 0x27
    0,              // Scan Code 0x28
    0,              // Scan Code 0x29
    0,              // Scan Code 0x2A
    0,              // Scan Code 0x2B
    0,              // Scan Code 0x2C
    0,              // Scan Code 0x2D
    0,              // Scan Code 0x2E
    0,              // Scan Code 0x2F
    0,              // Scan Code 0x30
    0,              // Scan Code 0x31
    0,              // Scan Code 0x32
    0,              // Scan Code 0x33
    0,              // Scan Code 0x34
    0,              // Scan Code 0x35
    0,              // Scan Code 0x36
    0,              // Scan Code 0x37
    0,              // Scan Code 0x38
    0,              // Scan Code 0x39
    0,              // Scan Code 0x3A
    0,              // Scan Code 0x3B
    0,              // Scan Code 0x3C
    0,              // Scan Code 0x3D
    0,              // Scan Code 0x3E
    0,              // Scan Code 0x3F
#endif
#ifdef KEDPAD_C02
    0,              // Scan Code 0x0, Prog
    VK_APP3,        // Scan Code 0x1
    VK_TSOFT1,      // Scan Code 0x2
    VK_TLEFT,       // Scan Code 0x3
    VK_APP1,        // Scan Code 0x4
    0,              // Scan Code 0x5
    0,              // Scan Code 0x6
    0,              // Scan Code 0x7
    0,              // Scan Code 0x8
    VK_TVOLUMEUP,   // Scan Code 0x9
    VK_TUP,         // Scan Code 0xA
    VK_TACTION,     // Scan Code 0xB
    VK_TDOWN,       // Scan Code 0xC
    0,              // Scan Code 0xD
    0,              // Scan Code 0xE
    0,              // Scan Code 0xF
    0,              // Scan Code 0x10
    VK_TVOLUMEDOWN, // Scan Code 0x11
    VK_TSOFT2,      // Scan Code 0x12
    VK_TRIGHT,      // Scan Code 0x13
    VK_APP2,        // Scan Code 0x14
    0,              // Scan Code 0x15
    0,              // Scan Code 0x16
    0,              // Scan Code 0x17
    0,              // Scan Code 0x18
    0,              // Scan Code 0x19
    0,              // Scan Code 0x1A
    VK_TTALK,       // Scan Code 0x1B
    VK_TEND,        // Scan Code 0x1C
    0,              // Scan Code 0x1D
    0,              // Scan Code 0x1E
    0,              // Scan Code 0x1F
    0,              // Scan Code 0x20
    0,              // Scan Code 0x21
    0,              // Scan Code 0x22
    0,              // Scan Code 0x23
    0,              // Scan Code 0x24
    0,              // Scan Code 0x25
    0,              // Scan Code 0x26
    0,              // Scan Code 0x27
    0,              // Scan Code 0x28
    0,              // Scan Code 0x29
    0,              // Scan Code 0x2A
    0,              // Scan Code 0x2B
    0,              // Scan Code 0x2C
    0,              // Scan Code 0x2D
    0,              // Scan Code 0x2E
    0,              // Scan Code 0x2F
    0,              // Scan Code 0x30
    0,              // Scan Code 0x31
    0,              // Scan Code 0x32
    0,              // Scan Code 0x33
    0,              // Scan Code 0x34
    0,              // Scan Code 0x35
    0,              // Scan Code 0x36
    0,              // Scan Code 0x37
    0,              // Scan Code 0x38
    0,              // Scan Code 0x39
    0,              // Scan Code 0x3A
    0,              // Scan Code 0x3B
    0,              // Scan Code 0x3C
    0,              // Scan Code 0x3D
    0,              // Scan Code 0x3E
    0,              // Scan Code 0x3F
#endif
};

//------------------------------------------------------------------------------
// Long press remap
//static UCHAR off[]     = { VK_TEND };
static UCHAR speaker[] = { VK_TTALK };

UCHAR vkApp4[1] = { VK_APP3 };

static KEYPAD_REMAP_ITEM longRemapItems[] = {
//    { VK_TPOWER, dimof(off),     3000, off     },
    { VK_F16,    dimof(speaker), 1000, speaker },
    { VK_APP4,    dimof(vkApp4), 1000, vkApp4 },
};

KEYPAD_REMAP g_sKpdLngRmp = { dimof(longRemapItems), longRemapItems };


// Dial unmask key while sleeping
static KEYPAD_DIAL_WAKEUP g_sKpdDlUnmask[] = {
      {VK_TTALK, TRUE}
    , {VK_TEND , TRUE}
    , {VK_TVOLUMEUP, FALSE}
    , {VK_TVOLUMEDOWN, FALSE}
};

KEYPAD_DIAL_UNMASK g_KpdUnmask = {dimof(g_sKpdDlUnmask), g_sKpdDlUnmask};

//------------------------------------------------------------------------------
static UINT8 dnKeysAction[] = { VK_ACTION, VK_TACTION };
static UINT8 upKeysAction[] = { VK_TACTION, VK_ACTION };

static KEYPAD_MULTI_KEYS actionKeyDn = { dimof(dnKeysAction), dnKeysAction };
static KEYPAD_MULTI_KEYS actionKeyUp = { dimof(upKeysAction), upKeysAction };

#ifdef KEYPAD_IMGPPC

static UINT8 dnKeysApp1[] = { VK_LWIN, VK_APP1 };
static UINT8 upKeysApp1[] = { VK_APP1, VK_LWIN };

static KEYPAD_MULTI_KEYS app1KeyDn   = { dimof(dnKeysApp1), dnKeysApp1 };
static KEYPAD_MULTI_KEYS app1KeyUp   = { dimof(upKeysApp1), upKeysApp1 };

static UINT8 dnKeysApp2[] = { VK_LWIN, VK_APP2 };
static UINT8 upKeysApp2[] = { VK_APP2, VK_LWIN };

static KEYPAD_MULTI_KEYS app2KeyDn   = { dimof(dnKeysApp2), dnKeysApp2 };
static KEYPAD_MULTI_KEYS app2KeyUp   = { dimof(upKeysApp2), upKeysApp2 };

static UINT8 dnKeysApp3[] = { VK_LWIN, VK_APP3 };
static UINT8 upKeysApp3[] = { VK_APP3, VK_LWIN };

static KEYPAD_MULTI_KEYS app3KeyDn   = { dimof(dnKeysApp3), dnKeysApp3 };
static KEYPAD_MULTI_KEYS app3KeyUp   = { dimof(upKeysApp3), upKeysApp3 };

static UINT8 dnKeysApp4[] = { VK_LWIN, VK_APP4 };
static UINT8 upKeysApp4[] = { VK_APP4, VK_LWIN };

static KEYPAD_MULTI_KEYS app4KeyDn   = { dimof(dnKeysApp4), dnKeysApp4 };
static KEYPAD_MULTI_KEYS app4KeyUp   = { dimof(upKeysApp4), upKeysApp4 };

#endif

static UINT8 pressKeysUp[] = { VK_UP, VK_DPAD };

static KEYPAD_MULTI_KEYS upKeyPress     = { dimof(pressKeysUp), pressKeysUp };

static UINT8 pressKeysDown[] = { VK_DOWN, VK_DPAD };

static KEYPAD_MULTI_KEYS downKeyPress   = { dimof(pressKeysDown), pressKeysDown };

static UINT8 pressKeysLeft[] = { VK_LEFT, VK_DPAD };

static KEYPAD_MULTI_KEYS leftKeyPress   = { dimof(pressKeysLeft), pressKeysLeft };

static UINT8 pressKeysRight[] = { VK_RIGHT, VK_DPAD };

static KEYPAD_MULTI_KEYS rightKeyPress  = { dimof(pressKeysRight), pressKeysRight };

static UINT8 pressKeysRockUp[] = { VK_UP, VK_ROCKER };

static KEYPAD_MULTI_KEYS rockUpKeyPress  = { dimof(pressKeysRockUp), pressKeysRockUp };

static UINT8 pressKeysRockDn[] = { VK_DOWN, VK_ROCKER };

static KEYPAD_MULTI_KEYS rockDnKeyPress  = { dimof(pressKeysRockDn), pressKeysRockDn };



static KEYPAD_MULTI_ITEM g_sMultiItems[] = {
    { VK_TACTION,   &actionKeyDn,    &actionKeyUp }
    ,{ VK_UP,       &upKeyPress,     &upKeyPress }
    ,{ VK_DOWN,     &downKeyPress,   &downKeyPress }
    ,{ VK_LEFT,     &leftKeyPress,   &leftKeyPress }
    ,{ VK_RIGHT,    &rightKeyPress,  &rightKeyPress }
    ,{ VK_ROCKACT,  &actionKeyDn,    &actionKeyUp }
    ,{ VK_ROCKUP,   &rockUpKeyPress, &rockUpKeyPress }
    ,{ VK_ROCKDN,   &rockDnKeyPress, &rockDnKeyPress }
#ifdef OEM_CAMERA_AUTO_FOCUS_KEY
    ,{ VK_FOCUS,    NULL,         NULL }
#endif
#ifdef KEYPAD_IMGPPC
    ,{ VK_APP1,     &app1KeyDn,   &app1KeyUp }
    ,{ VK_APP2,     &app2KeyDn,   &app2KeyUp }
    ,{ VK_APP3,     &app3KeyDn,   &app3KeyUp }
    ,{ VK_APP4,     &app4KeyDn,   &app4KeyUp }
#endif
};

KEYPAD_MULTI g_sKpdMulti = { dimof(g_sMultiItems), g_sMultiItems };


//------------------------------------------------------------------------------

static UCHAR softkeys[] = { VK_TSOFT1, VK_TSOFT2 };

static KEYPAD_REPEAT_BLOCK softkeyBlock = { dimof(softkeys), softkeys };

static KEYPAD_REPEAT_ITEM repeatItems[] = {
    { VK_TBACK,       FALSE, NULL,             NULL },
    { VK_TVOLUMEUP,   FALSE, NULL,             NULL },
    { VK_TVOLUMEDOWN, FALSE, NULL,             NULL },
    { VK_TUP,         FALSE, &upKeyPress,      &softkeyBlock },
    { VK_TRIGHT,      FALSE, &rightKeyPress,   &softkeyBlock },
    { VK_TLEFT,       FALSE, &leftKeyPress,    &softkeyBlock },
    { VK_TDOWN,       FALSE, &downKeyPress,    &softkeyBlock },
    { VK_ROCKUP,      FALSE, &rockUpKeyPress,  &softkeyBlock },
    { VK_ROCKDN,      FALSE, &rockDnKeyPress,  &softkeyBlock }
};

KEYPAD_REPEAT g_sKpdRpt = { dimof(repeatItems), repeatItems };


static UCHAR silentKeys[] =
    { VK_LWIN
    , VK_ACTION
    , VK_DPAD
    , VK_ROCKER };

KEYPAD_SILENT g_sKpdSlnt = { dimof(silentKeys), silentKeys };


//-----------------------------------------------------------------------------
volatile IOCMG_REG   *g_pIocmgReg = NULL;

//-----------------------------------------------------------------------------
//
// Function: InitIocmgRegister
//
// This function initialize iocmg register to select KPC function and push up IO.
//
// Parameters:
//     None.
//
// Returns:
//     N/A.
//
//-----------------------------------------------------------------------------
BOOL InitIocmgRegister(VOID)
{
    PHYSICAL_ADDRESS PA;

    PA.QuadPart = IOCMG_BASE_REG;
    g_pIocmgReg = (IOCMG_REG *) HiMmMapIoSpace(PA, sizeof(IOCMG_REG), FALSE);

    // if remaping failed, release the memory.
    if(NULL == g_pIocmgReg)
    {
        NKDbgPrintfW(TEXT("[Error Keypad]InitIocmgRegister: Map Iomg register error!\r\n"));
        return FALSE;
    }

#ifdef KEDPAD_B831
    // select KPC function
    OUTKPCREG(&g_pIocmgReg->adwIomg[23], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[24], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[25], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[26], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[27], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[28], 1);        // Reversed for Power gating
    OUTKPCREG(&g_pIocmgReg->adwIomg[29], 1);        // Reversed for IrDA shutdown
    OUTKPCREG(&g_pIocmgReg->adwIomg[30], 1);        // Reversed for Touch panel

    OUTKPCREG(&g_pIocmgReg->adwIomg[31], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[32], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[33], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[34], 1);
    OUTKPCREG(&g_pIocmgReg->adwIomg[35], 1);        // Reversed for Touch panel
    OUTKPCREG(&g_pIocmgReg->adwIomg[36], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[37], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[38], 1);        // Reversed for Mobile TV

    // push up, enable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[94], 0x7);
    OUTKPCREG(&g_pIocmgReg->adwIocg[95], 0x7);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[96], 0x7);    // Reversed for Power gating
    //OUTKPCREG(&g_pIocmgReg->adwIocg[97], 0x7);    // Reversed for IrDA shutdown
    //OUTKPCREG(&g_pIocmgReg->adwIocg[98], 0x7);    // Reversed for Touch panel

    // push up, disable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[99], 0x0);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[100], 0x3);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[101], 0x3);   // Reversed for Touch panel
    //OUTKPCREG(&g_pIocmgReg->adwIocg[102], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[103], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[104], 0x3);   // Reversed for Mobile TV
#endif
#if defined KEDPAD_MOBILEXP || defined KEDPAD_C02
    // select KPC function
    OUTKPCREG(&g_pIocmgReg->adwIomg[23], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[24], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[25], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[26], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[27], 1);
    OUTKPCREG(&g_pIocmgReg->adwIomg[28], 1);        // Reversed for Power gating
    OUTKPCREG(&g_pIocmgReg->adwIomg[29], 1);        // Reversed for IrDA shutdown
    OUTKPCREG(&g_pIocmgReg->adwIomg[30], 1);        // Reversed for Touch panel

    OUTKPCREG(&g_pIocmgReg->adwIomg[31], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[32], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[33], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[34], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[35], 0);        // Reversed for Touch panel
    OUTKPCREG(&g_pIocmgReg->adwIomg[36], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[37], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[38], 1);        // Reversed for Mobile TV

    // push up, enable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[94], 0x7);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[95], 0x7);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[96], 0x7);    // Reversed for Power gating
    //OUTKPCREG(&g_pIocmgReg->adwIocg[97], 0x7);    // Reversed for IrDA shutdown
    //OUTKPCREG(&g_pIocmgReg->adwIocg[98], 0x7);    // Reversed for Touch panel

    // push up, disable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[99], 0x0);
    OUTKPCREG(&g_pIocmgReg->adwIocg[100], 0x0);
    OUTKPCREG(&g_pIocmgReg->adwIocg[101], 0x0);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[102], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[103], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[104], 0x3);   // Reversed for Mobile TV
#endif
#ifdef KEDPAD_TERMINAL
    // select KPC function
    OUTKPCREG(&g_pIocmgReg->adwIomg[23], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[24], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[25], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[26], 1);
    OUTKPCREG(&g_pIocmgReg->adwIomg[27], 1);
    OUTKPCREG(&g_pIocmgReg->adwIomg[28], 1);        // Reversed for Power gating
    OUTKPCREG(&g_pIocmgReg->adwIomg[29], 1);        // Reversed for IrDA shutdown
    OUTKPCREG(&g_pIocmgReg->adwIomg[30], 1);        // Reversed for Touch panel

    OUTKPCREG(&g_pIocmgReg->adwIomg[31], 1);
    OUTKPCREG(&g_pIocmgReg->adwIomg[32], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[33], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[34], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[35], 0);
    OUTKPCREG(&g_pIocmgReg->adwIomg[36], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[37], 1);        // Reversed for Mobile TV
    OUTKPCREG(&g_pIocmgReg->adwIomg[38], 1);        // Reversed for Mobile TV

    // push up, enable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[94], 0x7);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[95], 0x7);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[96], 0x7);    // Reversed for Power gating
    //OUTKPCREG(&g_pIocmgReg->adwIocg[97], 0x7);    // Reversed for IrDA shutdown
    //OUTKPCREG(&g_pIocmgReg->adwIocg[98], 0x7);    // Reversed for Touch panel

    // push up, disable input
    OUTKPCREG(&g_pIocmgReg->adwIocg[99], 0x0);
    OUTKPCREG(&g_pIocmgReg->adwIocg[100], 0x0);
    OUTKPCREG(&g_pIocmgReg->adwIocg[101], 0x0);
    //OUTKPCREG(&g_pIocmgReg->adwIocg[102], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[103], 0x3);   // Reversed for Mobile TV
    //OUTKPCREG(&g_pIocmgReg->adwIocg[104], 0x3);   // Reversed for Mobile TV
#endif

    HiMmUnmapIoSpace((PVOID)g_pIocmgReg, sizeof(IOCMG_REG));
    g_pIocmgReg = NULL;

    return TRUE;
}

